home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / modulog / modulog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-23  |  2.3 KB  |  109 lines

  1. /*
  2.  * modulog --
  3.  *
  4.  *    This program is invoked at boot time to invalidate the user log
  5.  *    entry for the current host.  It can also be used to change the
  6.  *    user log manually in other ways; see the man page.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <host.h>
  11. #include <ulog.h>
  12. #include <db.h>
  13. #include <syslog.h>
  14. #include <option.h>
  15. #include <sys/time.h>
  16. #include <pwd.h>
  17. #include <string.h>
  18.  
  19. extern int errno;
  20. extern char *sys_errlist[];
  21.  
  22. int port = 0;
  23. char *user = NULL;
  24. char *location = NULL;
  25. int clearAll = 0;
  26. int invalidate = 0;
  27.  
  28. Option optionArray[] = {
  29.     {OPT_INT, "p", (char *)&port,
  30.          "Port to modify (default is console)."},
  31.     {OPT_STRING, "u", (char *)&user,
  32.          "User to \"log in\" (default is current user)."},
  33.     {OPT_TRUE, "i", (char *)&invalidate,
  34.          "Invalidate the  log entry for the specified port."},
  35.     {OPT_STRING, "l", (char *)&location,
  36.          "Create a log entry for the specified port and user at this location."},
  37.     {OPT_TRUE, "C", (char *)&clearAll,
  38.          "Clear all entries for current host."},
  39. };
  40. static int numOptions = sizeof(optionArray) / sizeof(Option);
  41.  
  42. #define BUFSIZE 256
  43.  
  44. main(argc, argv)
  45.     int argc;
  46.     char **argv;
  47. {
  48.     int             status;
  49.     int         i;
  50.     Host_Entry        *entryPtr;
  51.     struct passwd    *pwdPtr;
  52.     char        hostname[BUFSIZE];
  53.     int            userID;    
  54.  
  55.     argc = Opt_Parse(argc, argv, optionArray, numOptions,
  56.                OPT_ALLOW_CLUSTERING);
  57.  
  58.  
  59.     if (port < 0 || port > ULOG_MAX_PORTS) {
  60.     (void) fprintf(stderr, "Invalid port: %d.\n", port);
  61.     exit(1);
  62.     }
  63.  
  64.     if (gethostname(hostname, sizeof(hostname)) < 0) {
  65.     syslog(LOG_ERR, "error getting hostname.\n");
  66.     perror("gethostname");
  67.     exit(1);
  68.     }
  69.     entryPtr = Host_ByName(hostname);
  70.     if (entryPtr == (Host_Entry *) NULL) {
  71.     syslog(LOG_ERR, "Error getting host information for '%s'.\n",
  72.            hostname);
  73.     exit(1);
  74.     }
  75.  
  76.     if (user != NULL) {
  77.     pwdPtr = getpwnam(user);
  78.     if (pwdPtr == (struct passwd *) NULL) {
  79.         (void) fprintf(stderr, "Invalid user: %s.\n", user);
  80.         exit(1);
  81.     }
  82.     userID = pwdPtr->pw_uid;
  83.     } else {
  84.     userID = getuid();
  85.     }
  86.  
  87.     
  88.     if (invalidate) {
  89.     if (Ulog_RecordLogout(0, port) < 0) {
  90.         perror("Error in Ulog_RecordLogout");
  91.     }
  92.     } else if (location) {
  93.     if (Ulog_RecordLogin(userID, location, port) < 0) {
  94.         perror("Error in Ulog_RecordLogin");
  95.     }
  96.     } else {
  97.     if (Ulog_ClearLogins() < 0) {
  98.         perror("Error in Ulog_ClearLogins");
  99.     }
  100.     }
  101.     exit(0);
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.